//------------------------------------------------------------------------------
#include "CResponse.h"
//------------------------------------------------------------------------------
CResponse* CResponse::fromVariant(QVariant v) {
	CResponse *r=new CResponse();
	r->setData(QVariant());
	
	r->setErrorCode(-1);
	r->setErrorMessage(QObject::tr("JSon message is not a lottux response"));
	
	if(v.type() == QVariant::Map) {
		QVariantMap m=qvariant_cast<QVariantMap>(v);
		if(m.contains("data") && m.contains("errorResponse") && m.value("data").canConvert(QVariant::List)) {
			r->setData(m.value("data"));
			
			QVariantMap errorResponse=qvariant_cast<QVariantMap>(m.value("errorResponse"));
				
			r->setErrorCode(errorResponse.value("errorCode").toInt());
			r->setErrorMessage(errorResponse.value("message").toString());
		}
	}
	
	return r;
}
//------------------------------------------------------------------------------